<?php
require_once("header.php");
require_once("config.php");
require_once("utils.php");
$tag_id=$_GET['q'];
$db=new SQLite3($dbfilename);
$query="SELECT value FROM tag_t WHERE tag_id='$tag_id';";
$results=$db->query($query);
$res=$results->fetchArray(SQLITE3_ASSOC);
echo "These files have the " ;
show_tag(-1,$tag_id,$res['value']);
echo " tag<br>";

$query="SELECT i.* FROM item_t i, map_t m WHERE (m.tag_id='$tag_id' AND  i.item_id=m.item_id) GROUP BY i.item_id;";
$results=$db->query($query);

while($res = $results->fetchArray(SQLITE3_ASSOC)){
	$pfn = $res['pfn'];
	echo "<a href=\"$pfn\">" . basename($pfn) . "</a>";
	// TODO: "remove tag from this file"
	echo "<br>";

}
$db->close();
require_once("footer.php");